<!DOCTYPE html>
            
<HTML>
<HEAD>
<meta name="booktitle" content="Developing Applications With Objective Caml" >
 <meta charset="ISO-8859-1"><meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
<META name="GENERATOR" content="hevea 1.05-7 of 2000-02-24">
<META NAME="Author" CONTENT="Christian.Queinnec@lip6.fr">
<LINK rel=stylesheet type="text/css" href="videoc-ocda.css">
<script language="JavaScript" src="videoc.js"><!--
//--></script>
<TITLE>
 Introduction
</TITLE>
</HEAD>
<BODY class="regularBody">
<A HREF="book-ora136.html"><IMG SRC ="previous_motif.gif" ALT="Previous"></A>
<A HREF="index.html"><IMG SRC ="contents_motif.gif" ALT="Contents"></A>
<A HREF="book-ora139.html"><IMG SRC ="next_motif.gif" ALT="Next"></A>
<HR>

<H2> Introduction</H2>
As you may have guessed from the name, Objective CAML supports object-oriented programming.
Unlike imperative programming, in which execution is driven by explicit sequencing
of operations, or functional programming, where it is driven by the required
computations, object-oriented programming can be thought of as data driven.
Using objects introduces a new organization of programs into
classes of related objects.
A class groups together data and operations.
The latter, also known as <EM>methods</EM>, define the possible behaviors of an
object. A method is invoked
by <EM>sending a message</EM> to an object. When an object receives
a message, it performs the action or the computation corresponding to the method
specified by the message. This is different from applying a function to arguments
because a message (which contains the method name) is sent to an object. It is up to
the object itself to determine the code that will actually be executed; such a
<EM>delayed</EM> binding between name and code makes behavior
more adaptable and code easier to reuse.<BR>
<BR>
With object-oriented programming, relations are defined between
classes. Classes also define how objects communicate through message parameters.
Aggregation and inheritance relations between classes
allow new kinds of application modeling. A class that inherits
from another class includes all definitions from the parent's class. However, it may extend
the set of data and methods and redefine inherited behaviors, provided typing
constraints are respected.
We will use a graphical notation<A NAME="text37" HREF="book-ora150.html#note37"><SUP><FONT SIZE=2>1</FONT></SUP></A> to represent
relations between classes.<BR>
<BR>
Objective CAML's object extensions are integrated with the type system of the language:
a class declaration defines a type with the same name as the class.
Two kinds of polymorphism coexist. One of them is parametric polymorphism,
which we have already seen with parameterized types: parameterized classes.
The other one, known as inclusion polymorphism, uses the subtyping
relation between objects and delayed binding. If the type of the class
<I>sc</I> is a subtype of the class <I>c</I> then any object from <I>sc</I> may
be used in place of an object from <I>c</I>. The subtype constraint must
be stated explicitly. Inclusion polymorphism makes it possible to
construct non-homogeneous lists where the type of each element is a subtype
of a type common to all list elements. Since binding is delayed,
sending the same message to all elements of such a list can activate different
methods according to the sub-classes of the actual elements.<BR>
<BR>
On the other hand, Objective CAML does not include the notion of method overloading,
which would allow several definitions for one method name. Without this restriction,
type inference might encounter ambiguous situations requiring
additional information from the programmer.<BR>
<BR>
It should be emphasized that Objective CAML is the only language with an object
extension that provides both parameterized and inclusion polymorphism, while still being
fully statically typed through type inference.<BR>
<BR>
<HR>
<A HREF="book-ora136.html"><IMG SRC ="previous_motif.gif" ALT="Previous"></A>
<A HREF="index.html"><IMG SRC ="contents_motif.gif" ALT="Contents"></A>
<A HREF="book-ora139.html"><IMG SRC ="next_motif.gif" ALT="Next"></A>
</BODY>
</HTML>
